package com.atguigu.yygh.hosp.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;

import io.swagger.annotations.ApiOperation;



@RestController
@RequestMapping("/admin/hosp/hospital")
//@CrossOrigin  //允许跨域访问
public class HostpitalController {

	@Autowired
	private HospitalService hospitalService;
	
	//医院列表  条件查询 带分页
	@PostMapping("/list/{page}/{limit}")
	public Result listHospital(@PathVariable(value = "page") Integer page,
                               @PathVariable(value = "limit") Integer limit,
                               @RequestBody(required = false) HospitalQueryVo hospitalQueryVo){
		
		Page<Hospital> pageList = hospitalService.selectHospitalPage(page, limit, hospitalQueryVo);
		return Result.ok(pageList);
	}
	
	
	
	
	//更新医院上线状态
	@ApiOperation(value = "更新医院上线状态")
	@PutMapping("/updateHospStatus/{id}/{status}")
	public Result updateHospStatus(@PathVariable(value = "id") String id,@PathVariable(value = "status") Integer status){
		hospitalService.updateStatus(id, status);
		return Result.ok();
	}
	
	//医院详情 信息
	@ApiOperation(value = "医院详情信息")
	@GetMapping("/showHospDetail/{id}")
	public Result showHospDetail(@PathVariable(value = "id") String id){
		Map<String,Object> map = hospitalService.getHospById(id);
		return Result.ok(map);
	}
	
}
